#include "NxService.h"
#include "../utils/NxHttp.h"
#include <sstream>

const char* NJGIS::SERVICE::NjService::getIP()
{
	return this->_ip.c_str();
}

int NJGIS::SERVICE::NjService::getPort()
{
	return this->_port;
}

int NJGIS::SERVICE::NjService::getPortStr( std::string &port )
{
	std::stringstream ss;
	ss << this->_port;
	ss >> port;
	return 1;
}



int NJGIS::SERVICE::NjService::getBaseUrl( std::string &url )
{
	std::string strport;
	this->getPortStr(strport);
	url = "http://" + this->_ip + ":" + strport + "/";
	return 1;
}

int NJGIS::SERVICE::NjService::connect()
{
	std::string url = "";
	this->getBaseUrl(url);
	url = url + "ping";
	std::string body = "";
	NjHttpHelper::request_get_sync(url.c_str(), body);
	if (body == "OK")
	{
		return 1;
	}
	return 0;
}

int NJGIS::SERVICE::NjService::setIP( const char* ip )
{
	this->_ip = ip;
	return 1;
}

int NJGIS::SERVICE::NjService::setPort( const int port )
{
	this->_port = port;
	return 1;
}
